//
//  classifyView.m
//  mintHome
//
//  Created by 朱彦名 on 16/6/16.
//  Copyright © 2016年 朱彦名. All rights reserved.
//

#import "classifyView.h"
#import "scrollView.h"
#import "viewOfTop.h"
#import "viewOfMid.h"
#import "viewOfBottom.h"
#import "modelOfTopImage.h"
#import "nextPageView.h"
#import "collectionViewOfMid.h"
#import "collectionOfBottom.h"
@interface classifyView ()

@property (nonatomic, retain) viewOfTop *topView;
@property (nonatomic, retain) NSMutableArray * arrOfTopImage;
@property (nonatomic, retain) viewOfMid *midView;
@property (nonatomic, retain) viewOfBottom *bottomView;
@property (nonatomic, retain) nextPageView *nextAllPage;
@property (nonatomic, retain) UIButton *buttonOfMid;
@property (nonatomic, retain) UILabel *labelOfMid;
@property (nonatomic, retain) UIButton *buttonOfBtm;
@property (nonatomic, retain) UILabel *labelOfBtm;



@end

@implementation classifyView

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"分类";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(handleSearch:)];;
    
    [self creatTopView];
    [self creatMidView];
    [self creatBottomView];
    



    
    
    
}
- (void)handleSearch: (UIBarButtonItem *)button{

    NSLog(@"搜索");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - 布局
- (void)creatTopView{
    
    self.topView = [[viewOfTop alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, (SCREEN_HEIGHT - 114) / 3)];
    [self.view addSubview:self.topView];
    
    
    [self.topView.buttonOfRight addTarget:self action:@selector(passNextPage:) forControlEvents:UIControlEventTouchDown];
    
    self.topView.albumOfTop = [[album alloc]initWithFrame:CGRectMake(0, 15, SCREEN_WIDTH, self.topView.bounds.size.height- 35) withImage:[self handleImage]];
    [self.topView addSubview:self.topView.albumOfTop];
    

    

}
- (void)creatMidView{

    self.midView = [[viewOfMid alloc]initWithFrame:CGRectMake(0, 64 + (SCREEN_HEIGHT - 114) / 3, SCREEN_WIDTH, (SCREEN_HEIGHT - 114) / 3)];
    [self.view addSubview:self.midView];
    
    

    collectionViewOfMid *midCol = [[collectionViewOfMid alloc]init];
    
    [self addChildViewController:midCol];
    midCol.collectionView.frame = CGRectMake(0, 30, self.midView.bounds.size.width, self.midView.bounds.size.height);
    [self.midView addSubview:midCol.collectionView];
    midCol.collectionView.backgroundColor = [UIColor whiteColor];
    

    
    
}
- (void)passNextPage: (UIButton *)button{

    self.nextAllPage = [[nextPageView alloc]init];
    [self.navigationController pushViewController:self.nextAllPage animated:YES];
    
    NSLog(@"跳转");
}

- (void)creatBottomView{
    self.bottomView = [[viewOfBottom alloc]initWithFrame:CGRectMake(0, 64 + (SCREEN_HEIGHT - 114) / 3 * 2 , SCREEN_WIDTH, (SCREEN_HEIGHT - 114) / 3)];
    [self.view addSubview:self.bottomView];
    
    collectionOfBottom *btmCol = [[collectionOfBottom alloc]init];
    
    btmCol.collectionView.frame = CGRectMake(0, 30, self.bottomView.bounds.size.width, self.bottomView.bounds.size.height);
    
    [self addChildViewController:btmCol];
    
    [self.bottomView addSubview:btmCol.collectionView];
    btmCol.collectionView.backgroundColor = [UIColor whiteColor];
    
}
#pragma mark - 解析数据
- (NSArray *)handleImage{
    self.arrOfTopImage = [NSMutableArray array];
    
    NSURL *url = [NSURL URLWithString:@"http://api.bohejiaju.com/v1/collections?limit=20&offset=0"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    
    NSArray *arrOfData = result[@"data"][@"collections"];
    
    for (int i = 0 ; i < 5; i++) {
        NSDictionary *dic = [arrOfData objectAtIndex:i];
        modelOfTopImage *model = [[modelOfTopImage alloc]initWithDic:dic];
        
        NSURL *url1 = [NSURL URLWithString:model.banner_image_url];
        NSData *data = [NSData dataWithContentsOfURL:url1];
        UIImage *images = [UIImage imageWithData:data];
        [self.arrOfTopImage addObject:images];
    }
    return self.arrOfTopImage;
    
}

- (void)setLightDay{
    NSLog(@"%s",__func__);
    
    [NightManager setBackgroundColorWithView:self.view];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
    
}
- (void)setNightDay{
    NSLog(@"%s",__func__);
    
    
    [NightManager setBackgroundColorWithView:self.view];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
}
@end
